
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>

<div class="panel " style="margin-bottom:0;">
	<div class="panel-body pan" style="/*height: 305px*/">
	<div class="form-body pal">
		<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
			<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">直播间名称
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="liveTitle" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">直播间公告
					<span class='require'></span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<textarea id="liveNotice"  rows="3" cols="20" class="form-control" ></textarea> 
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
					<label for="inputUsername" class="col-md-3 control-label">封面图片
					</label>
					<div class="col-md-9">
						<div>
							<div style="display:inline " id="single"></div>
							<butten onclick="upImages()" style="Float:left;font-size: 12px;border: 0;" data-toggle="dropdown" class="btn btn-success dropdown-toggle">上传图片</butten>
							<!-- <input type="button" style="width: 70px;height: 27px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;font-size:12px" class="btn btn-success dropdown-toggle" onclick="upImages()" value="上传图片"/> -->
							<textarea id="uploadImage" name="uploadImage" style="display:none"></textarea>
							<input id="avatarImg" type="hidden" class="form-control" value="" />
						</div>
					</div>
				</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">直播间密码
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="livePassword" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">流媒体选择
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
					<input id="liveStreamTitle" type="text" class="form-control" disabled="disabled"/>
					<input id="liveStreamId"  type="hidden"/>
					<span class="input-group-btn">
						<butten  onclick="saveMedia()" style="Float:left;" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择</butten>
					</span> 
						
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">主播用户名
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="anchorUsername" type="text" class="form-control" disabled="disabled"/>
						<input id="anchorUsernameId"  type="hidden"/>
						<span class="input-group-btn">
							<butten  onclick="saveMember()" style="Float:left;" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择</butten>
						</span> 
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">主播编号
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="anchorNumber" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:none;">
				<label for="inputUsername" class="col-md-3 control-label">状态
					<span class='require'></span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="status" class="form-control" tyle="width: 80%;">
							<option value="0">待审核</option>
							<option value="1">审核通过</option>
							<option value="2">审核不通过</option>
						</select>
						<!-- <input id="status" type="text" class="form-control" /> -->
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 98%; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">直播间详情
					<span class='require'></span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<!-- <textarea id="liveHtml"  rows="3" cols="20" class="form-control" ></textarea>  -->
						<script id="liveHtml" type="text/plain" style="width:600px;"></script>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:none;">
				<label for="inputUsername" class="col-md-3 control-label">直播状态
					<span class='require'></span> </label>
				<div class="col-md-9">
					<div class="input-icon" id="statusLive">
						<select id="liveStatus" class="form-control" tyle="width: 80%;">
							<option value="0">停播中</option>
							<option value="1">直播中</option>
							<option value="2">禁播中</option>
						</select>
						<!-- <input id="liveStatus" type="text" class="form-control" /> -->
					</div>
				</div>
			</div>
			<!-- <div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">创建时间
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="createTime" type="text" class="form-control" type="hidden"/>
					</div>
				</div>
			</div>  -->
		<input id="createTime"  class="form-control" type="hidden"/>
		<input id="id" type="hidden" class="form-control" />
	</div>
</div>
<?} ?>
<script>
	var id = window.parent.getId();
	var curr = window.parent.getCurr();
	var _editor;
	var ue;
	
	$(function() {
		ue = UE.getEditor('liveHtml', {
	        initialFrameWidth: 720,
	        initialFrameHeight:350
	    });
		_editor = UE.getEditor('uploadImage');
		_editor.ready(function (){
		//设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
		_editor.setDisabled();
		//隐藏编辑器,因为只使用上传功能
		_editor.hide();
		//侦听图片上传
		_editor.addListener('beforeInsertImage',function(t,arg){
		for(var i=0;i<arg.length;i++){
			var urlPath = arg[i].src;
			var urlp = urlPath.indexOf("/upload");
			if(urlp!=-1){
				var imgPath = urlPath.substring(urlp,urlPath.length);
				$("#avatarImg").val(imgPath);
				$("#single").html("<img src='"+urlPath+"' width='30' height='30' />");
			}
		}
		});
		//侦听文件上传
		_editor.addListener('afterUpfile',function(t,arg){
			});
		});
		if (id != 0) {
			demo();
		}else{
			$("#liveStatus").attr("disabled","disabled").css("background-color","#EEEEEE;");
		}
	});
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	}
	function saveMember(){
		parent.layer.open({
			type : 2,
			area : [ '900px', '700px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"用户列表",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["zhibo_live_room_user.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  	iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function saveMedia(){
		parent.layer.open({
			type : 2,
			area : [ '900px', '700px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"媒体选择列表",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["zhibo_live_room_media.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  	iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function Page() {
		if ($.trim($("#liveTitle").val()).length < 1) { 
			alert('直播间名称不能为空！');
			return null;
		}
		if ($.trim($("#livePassword").val()).length < 1) {
			alert('直播间密码不能为空！');
			return null;
		}
		if ($.trim($("#liveStreamId").val()).length < 1) {
			alert('流媒体不能为空！');
			return null;
		}
		if ($.trim($("#anchorUsername").val()).length < 1) {
			alert('主播用户名不能为空！');
			return null;
		}
		if ($.trim($("#anchorNumber").val()).length < 1) {
			alert('主播编号不能为空！');
			return null;
		}
		$.ajax({
			type : "post",
			url : "addOrUploadLiveRoom.do",
			data : {
				"id" : id,
				"liveTitle":$("#liveTitle").val(),
				"liveNotice":$("#liveNotice").val(),
				"liveCover":$("#avatarImg").val(),
				"livePassword":$("#livePassword").val(),
				"liveStreamId":$("#liveStreamId").val(),
				"anchorUsername":$("#anchorUsername").val(),
				"anchorNumber":$("#anchorNumber").val(),
				"status":$("#status").val(),
				//"liveHtml":$("#liveHtml").val(),
				"liveHtml":ue.getContent(),
				"liveStatus":$("#liveStatus").val(),
				"createTime":$("#createTime").val()
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				if(data[0].data == 'yes'){
					window.parent.demo(curr);
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}else{
					parent.layer.msg('提交失败！请检查数据是否正确！');
				}
			},
			error : function(data) {
				parent.layer.msg('提交失败！请检查数据是否正确！');
			}
		});
	}
	function demo() {
		$.ajaxSettings.async = false; 
		$.getJSON('findLiveRoomList.do', {
			id : id
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#liveTitle").val(res[0].liveTitle);
			$("#liveNotice").val(res[0].liveNotice);
			$("#avatarImg").val(res[0].img);
			$("#single").html("<img src='"+res[0].liveCover+"' width='30' height='30'/>");
			$("#livePassword").val(res[0].livePassword);
			$("#liveStreamId").val(res[0].liveStreamId);
			$("#liveStreamTitle").val(res[0].liveStreamTitle);
			$("#anchorUsername").val(res[0].anchorUsername);
			$("#anchorNumber").val(res[0].anchorNumber);
			$("#status").val(res[0].status);
			$("#liveHtml").val(res[0].liveHtml);
			//ue.setContent(res[0].liveHtml);
			$("#id").val(res[0].id);
			$("#liveStatus").val(res[0].liveStatus);
			$("#createTime").val(res[0].createTime);
			
		});
	};
	
</script>


